<?php
class Payroll
{		
	
	public function __construct ()
	{
		
		
	}
	
	/**
	*	Funcion responsable de agregar el formulario de Client Information Form
	*	@autor: JJR
	*	@date: 01/26/2012
	*	@return:
	*/
    function listCompanySelect($code = '')
	{
		$sql = "SELECT hc.hdvc_code, hc.hdvc_nit, hc.hdvc_name,
                hc.hdvc_address, hc.hdvc_city, hc.state_code,
                hc.hdvc_description, hc.hdvc_date_create, hc.hdvc_status,
                cc.coco_admin
                FROM hdv_company hc, contract_company cc
                WHERE hc.hdvc_code = hc.hdvc_code
                AND hc.hdvc_code = ".$code;

		$consult  = mysql_query($sql);
		$array = '';
		$row = mysql_fetch_array($consult);
        
        
        $array->codigo             = $row['hdvc_code'];
        $array->nit                = $row['hdvc_nit'];
        $array->nombre             = $row['hdvc_name'];
        $array->direhcion          = $row['hdvc_address'];
        $array->ciudad             = $row['hdvc_city'];
        $array->departamento       = $row['state_code'];
        $array->descripcion        = $row['hdvc_description'];
        $array->fecha              = $row['hdvc_date_create'];
        $array->estado             = $row['hdvc_status'];
        $array->admin              = $row['coco_admin'];
        //print_r($array);die;				
		return $array;
	}
	
    function obtenerDatosEmpleados($code,$inicio,$fin)
    {
        $sql = "SELECT `hdv_name`, `hdv_lastname`, `hdv_cedula`, cont_sal_value, c.hdv_code
                FROM hdv he, contract c
                where he.hdv_code=c.hdv_code
                and c.hdvc_code=".$code;
   	    $consult  = mysql_query($sql);
		$datos = '';
        $i=0;
      	while($row = mysql_fetch_array($consult)){
        $datos[$i]->nombre             = $row['hdv_name'];
        $datos[$i]->apellido           = $row['hdv_lastname'];
        $datos[$i]->cedula             = $row['hdv_cedula'];
        $datos[$i]->basico             = $row['cont_sal_value'];
        $datos[$i]->codigo             = $row['hdv_code'];
        $sql2 = "SELECT lib_amount_payment
                 FROM libranza
                 WHERE lib_date_start >= '".$inicio."'
                 AND lib_date_end >= '".$fin."'
                 AND hdv_code =".$datos[$i]->codigo;
                 //echo ($sql2);die;
                 $consult2  = mysql_query($sql2);
                 $row2 = mysql_fetch_array($consult2);
        $datos[$i]->descuento          = $row2['lib_amount_payment'];
        $i++;
        }//print_r($datos);die;
         return $datos; 
    }
	function addPayroll($dataDetail){
		$sql = "INSERT INTO payroll (
		pay_date_ini,
        pay_date_end,
		pay_company)
		VALUES (
		'".$dataDetail->pay_date_ini."',
    	'".$dataDetail->pay_date_end."',
    	'".$dataDetail->pay_company."');";	
        //echo $sql;die;
		if(mysql_query($sql)){		
			return mysql_insert_id ();
		}else
			return false;
	}
    
    function addPayrollDetail($dataDetail){
		$sql = "INSERT INTO payroll_detail (
            pay_det_pay_id,
            pay_det_name, 
    		pay_det_idUser,
    		pay_det_salary,
            pay_det_days,
            pay_det_value_ign,
            pay_det_der,
            pay_det_aux,
            pay_det_con,
            pay_det_discount,
            pay_det_ah,
            pay_det_ap,
            pay_det_salud,
            pay_det_pension,
            pay_det_neto )
		VALUES ";
        $long = count($dataDetail);
        for($i=0;$i<$long;$i++)
        {
            $sql.="('".
            $dataDetail[$i]->pay_det_pay_id."','".
            $dataDetail[$i]->pay_det_name."','".
    		$dataDetail[$i]->pay_det_idUser."','".
    		$dataDetail[$i]->pay_det_salary."','".
            $dataDetail[$i]->pay_det_days."','".
            $dataDetail[$i]->pay_det_value_ign."','".
            $dataDetail[$i]->pay_det_der."','".
            $dataDetail[$i]->pay_det_aux."','".
            $dataDetail[$i]->pay_det_con."','".
            $dataDetail[$i]->pay_det_discount."','".
            $dataDetail[$i]->pay_det_ah."','".
            $dataDetail[$i]->pay_det_ap."','".
            $dataDetail[$i]->pay_det_salud."','".
            $dataDetail[$i]->pay_det_pension."','".
            $dataDetail[$i]->pay_det_neto."')";
            if($i < ($long-1)){
                $sql.=",";
            }
        }	//echo $sql;die;

		if(mysql_query($sql)){		
			return mysql_insert_id ();
		}else
			return false;
	}
	
	
}
?>